Passed
Pull Request — master (#30)
by
unknown
03:10
created

WaveFile.fromMpeg   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
// Type definitions for wavefile 11.0
2
// Project: https://github.com/rochars/wavefile
3
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars>
4
// Definitions: https://github.com/rochars/wavefile
5
6
export = wavefile;
7
8
declare module wavefile {
9
  class WaveFile {
10
    /**
11
     * The bit depth code according to the samples.
12
     * @type {string}
13
     */
14
    bitDepth: string;
15
    /**
16
     * The container identifier.
17
     * 'RIFF', 'RIFX' and 'RF64' are supported.
18
     * @type {string}
19
     */
20
    container: string;
21
    /**
22
     * @type {number}
23
     */
24
    chunkSize: number;
25
    /**
26
     * The format.
27
     * Always 'WAVE'.
28
     * @type {string}
29
     */
30
    format: string;
31
    /**
32
     * The data of the 'fmt' chunk.
33
     * @type {!Object<string, *>}
34
     */
35
    fmt: object;
36
    /**
37
     * The data of the 'fact' chunk.
38
     * @type {!Object<string, *>}
39
     */
40
    fact: object;
41
    /**
42
     * The data of the 'cue ' chunk.
43
     * @type {!Object<string, *>}
44
     */
45
    cue: object;
46
    /**
47
     * The data of the 'smpl' chunk.
48
     * @type {!Object<string, *>}
49
     */
50
    smpl: object;
51
    /**
52
     * The data of the 'bext' chunk.
53
     * @type {!Object<string, *>}
54
     */
55
    bext: object;
56
    /**
57
     * The data of the 'mext' chunk.
58
     * @type {!Object<string, *>}
59
     */
60
    mext: object;
61
    /**
62
     * The data of the 'cart' chunk.
63
     * @type {!Object<string, *>}
64
     */
65
    cart: object;
66
    /**
67
     * The data of the 'iXML' chunk.
68
     * @type {!Object<string, *>}
69
     */
70
    iXML: object;
71
    /**
72
     * The data of the 'ds64' chunk.
73
     * Used only with RF64 files.
74
     * @type {!Object<string, *>}
75
     */
76
    ds64: object;
77
    /**
78
     * The data of the 'data' chunk.
79
     * @type {!Object<string, *>}
80
     */
81
    data: object;
82
    /**
83
     * The data of the 'LIST' chunks.
84
     * Each item in this list look like this:
85
     *  {
86
     *    chunkId: '',
87
     *    chunkSize: 0,
88
     *    format: '',
89
     *    subChunks: []
90
     *   }
91
     * @type {!Array<!Object>}
92
     */
93
    LIST: object[];
94
    /**
95
     * The data of the 'junk' chunk.
96
     * @type {!Object<string, *>}
97
     */
98
    junk: object;
99
    /**
100
     * The data of the '_PMX' chunk.
101
     * @type {!Object<string, *>}
102
     */
103
    _PMX: object;
104
    /**
105
     * Whether to apply a pad byte or not
106
     * Defaults to 'true'
107
     * @type {boolean}
108
     */
109
     padBytes: boolean;
110
111
    /**
112
     * @param {Uint8Array=} [wavBuffer=null] A wave file buffer.
113
     * @throws {Error} If no 'RIFF' chunk is found.
114
     * @throws {Error} If no 'fmt ' chunk is found.
115
     * @throws {Error} If no 'data' chunk is found.
116
     */
117
    constructor(wavBuffer?: Uint8Array);
118
119
    /**
120
     * Return the samples packed in a Float64Array.
121
     * @param {boolean=} [interleaved=false] True to return interleaved samples,
122
     *   false to return the samples de-interleaved.
123
     * @param {Function=} [OutputObject=Float64Array] The sample container.
124
     * @return {!(Array|TypedArray)} the samples.
125
     */
126
    getSamples(interleaved?: boolean, OutputObject?: Function): Float64Array;
127
128
    /**
129
     * Return the sample at a given index.
130
     * @param {number} index The sample index.
131
     * @return {number} The sample.
132
     * @throws {Error} If the sample index is off range.
133
     */
134
    getSample(index: number): number;
135
136
    /**
137
     * Set the sample at a given index.
138
     * @param {number} index The sample index.
139
     * @param {number} sample The sample.
140
     * @throws {Error} If the sample index is off range.
141
     */
142
    setSample(index: number, sample: number): void;
143
144
    /**
145
     * Set up the WaveFileCreator object based on the arguments passed.
146
     * Existing chunks are reset.
147
     * @param {number} numChannels The number of channels.
148
     * @param {number} sampleRate The sample rate.
149
     *    Integers like 8000, 44100, 48000, 96000, 192000.
150
     * @param {string} bitDepthCode The audio bit depth code.
151
     *    One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
152
     *    or any value between '8' and '32' (like '12').
153
     * @param {!(Array|TypedArray)} samples The samples.
154
     * @param {Object=} options Optional. Used to force the container
155
     *    as RIFX with {'container': 'RIFX'}
156
     * @throws {Error} If any argument does not meet the criteria.
157
     */
158
    fromScratch(
159
      numChannels: number,
160
      sampleRate: number,
161
      bitDepthCode: string,
162
      samples:
163
        | Array<number>
164
        | Array<Array<number>>
165
        | ArrayLike<any>
166
        | Array<ArrayLike<any>>,
167
      options?: object
168
    ): void;
169
170
    /**
171
     * Set up the WaveFileCreator object from an mpeg buffer and/or optional info.
172
     * @param {!Uint8Array} mpegBuffer The buffer.
173
     * @param {Object=} info Optional Mpeg info such as version, layer,  etc.
174
     * @throws {Error} If the mpeg file cannot be parsed
175
     */
176
    fromMpeg(mpegBuffer: Uint8Array, info?: object): void;
177
178
    /**
179
     * Set up the WaveFileParser object from a byte buffer.
180
     * @param {!Uint8Array} wavBuffer The buffer.
181
     * @param {boolean=} [samples=true] True if the samples should be loaded.
182
     * @throws {Error} If container is not RIFF, RIFX or RF64.
183
     * @throws {Error} If format is not WAVE.
184
     * @throws {Error} If no 'fmt ' chunk is found.
185
     * @throws {Error} If no 'data' chunk is found.
186
     */
187
    fromBuffer(bytes: Uint8Array, samples?: boolean): void;
188
189
    /**
190
     * Return a byte buffer representig the WaveFileParser object as a .wav file.
191
     * The return value of this method can be written straight to disk.
192
     * @return {!Uint8Array} A wav file.
193
     * @throws {Error} If bit depth is invalid.
194
     * @throws {Error} If the number of channels is invalid.
195
     * @throws {Error} If the sample rate is invalid.
196
     */
197
    toBuffer(): Uint8Array;
198
199
    /**
200
     * Use a .wav file encoded as a base64 string to load the WaveFile object.
201
     * @param {string} base64String A .wav file as a base64 string.
202
     * @throws {Error} If any property of the object appears invalid.
203
     */
204
    fromBase64(base64String: string): void;
205
206
    /**
207
     * Return a base64 string representig the WaveFile object as a .wav file.
208
     * @return {string} A .wav file as a base64 string.
209
     * @throws {Error} If any property of the object appears invalid.
210
     */
211
    toBase64(): string;
212
213
    /**
214
     * Return a DataURI string representig the WaveFile object as a .wav file.
215
     * The return of this method can be used to load the audio in browsers.
216
     * @return {string} A .wav file as a DataURI.
217
     * @throws {Error} If any property of the object appears invalid.
218
     */
219
    toDataURI(): string;
220
221
    /**
222
     * Use a .wav file encoded as a DataURI to load the WaveFile object.
223
     * @param {string} dataURI A .wav file as DataURI.
224
     * @throws {Error} If any property of the object appears invalid.
225
     */
226
    fromDataURI(dataURI: string): void;
227
228
    /**
229
     * Force a file as RIFF.
230
     */
231
    toRIFF(): void;
232
233
    /**
234
     * Force a file as RIFX.
235
     */
236
    toRIFX(): void;
237
238
    /**
239
     * Change the bit depth of the samples.
240
     * @param {string} newBitDepth The new bit depth of the samples.
241
     *    One of '8' ... '32' (integers), '32f' or '64' (floats)
242
     * @param {boolean=} [changeResolution=true] A boolean indicating if the
243
     *    resolution of samples should be actually changed or not.
244
     * @throws {Error} If the bit depth is not valid.
245
     */
246
    toBitDepth(newBitDepth: string, changeResolution?: boolean): void;
247
248
    /**
249
     * Convert the sample rate of the file.
250
     * @param {number} sampleRate The target sample rate.
251
     * @param {Object=} options The extra configuration, if needed.
252
     */
253
    toSampleRate(samples: number, options?: object): void;
254
255
    /**
256
     * Encode a 16-bit wave file as 4-bit IMA ADPCM.
257
     * @throws {Error} If sample rate is not 8000.
258
     * @throws {Error} If number of channels is not 1.
259
     */
260
    toIMAADPCM(): void;
261
262
    /**
263
     * Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file.
264
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
265
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
266
     */
267
    fromIMAADPCM(bitDepthCode?: string): void;
268
269
    /**
270
     * Encode a 16-bit wave file as 8-bit A-Law.
271
     */
272
    toALaw(): void;
273
274
    /**
275
     * Decode a 8-bit A-Law wave file into a 16-bit wave file.
276
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
277
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
278
     */
279
    fromALaw(bitDepthCode?: string): void;
280
281
    /**
282
     * Encode 16-bit wave file as 8-bit mu-Law.
283
     */
284
    toMuLaw(): void;
285
286
    /**
287
     * Decode a 8-bit mu-Law wave file into a 16-bit wave file.
288
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
289
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
290
     */
291
    fromMuLaw(bitDepthCode?: string): void;
292
293
    /**
294
     * Write a RIFF tag in the INFO chunk. If the tag do not exist,
295
     * then it is created. It if exists, it is overwritten.
296
     * @param {string} tag The tag name.
297
     * @param {string} value The tag value.
298
     * @throws {Error} If the tag name is not valid.
299
     */
300
    setTag(tag: string, value: string): void;
301
302
    /**
303
     * Return the value of a RIFF tag in the INFO chunk.
304
     * @param {string} tag The tag name.
305
     * @return {?string} The value if the tag is found, null otherwise.
306
     */
307
    getTag(tag: string): string | null;
308
309
    /**
310
     * Return a Object<tag, value> with the RIFF tags in the file.
311
     * @return {!Object<string, string>} The file tags.
312
     */
313
    listTags(): object;
314
315
    /**
316
     * Remove a RIFF tag in the INFO chunk.
317
     * @param {string} tag The tag name.
318
     * @return {boolean} True if a tag was deleted.
319
     */
320
    deleteTag(tag: string): boolean;
321
322
    /**
323
     * Create a cue point in the wave file.
324
     * @param {!Object<string, *>} pointData The data of the cue point.
325
     */
326
    setCuePoint(pointData: object): void;
327
328
    /**
329
     * Remove a cue point from a wave file.
330
     * @param {number} index the index of the point. First is 1,
331
     *  second is 2, and so on.
332
     */
333
    deleteCuePoint(index: number): void;
334
335
    /**
336
     * Return an array with all cue points in the file, in the order they appear
337
     * in the file.
338
     * Objects representing cue points/regions look like this:
339
     *   {
340
     *     position: 500, // the position in milliseconds
341
     *     label: 'cue marker 1',
342
     *     end: 1500, // the end position in milliseconds
343
     *     dwName: 1,
344
     *     dwPosition: 0,
345
     *     fccChunk: 'data',
346
     *     dwChunkStart: 0,
347
     *     dwBlockStart: 0,
348
     *     dwSampleOffset: 22050, // the position as a sample offset
349
     *     dwSampleLength: 3646827, // the region length as a sample count
350
     *     dwPurposeID: 544106354,
351
     *     dwCountry: 0,
352
     *     dwLanguage: 0,
353
     *     dwDialect: 0,
354
     *     dwCodePage: 0,
355
     *   }
356
     * @return {!Array<Object>}
357
     */
358
    listCuePoints(): Array<object>;
359
360
    /**
361
     * Update the label of a cue point.
362
     * @param {number} pointIndex The ID of the cue point.
363
     * @param {string} label The new text for the label.
364
     */
365
    updateLabel(pointIndex: number, label: string): void;
366
367
    /**
368
     * Set the value of the iXML chunk.
369
     * @param {string} iXMLValue The value for the iXML chunk.
370
     * @throws {TypeError} If the value is not a string.
371
     */
372
    setiXML(iXMLValue: string): void;
373
374
    /**
375
     * Return the value of the iXML chunk.
376
     * @return {string} The contents of the iXML chunk.
377
     */
378
    getiXML(): string;
379
380
    /**
381
     * Set the value of the _PMX chunk.
382
     * @param {string} _PMXValue The value for the _PMX chunk.
383
     * @throws {TypeError} If the value is not a string.
384
     */
385
    set_PMX(_PMXValue: string): void;
386
387
    /**
388
     * Get the value of the _PMX chunk.
389
     * @return {string} The contents of the _PMX chunk.
390
     */
391
    get_PMX(): string;
392
  }
393
}
394